package com.nightonke.boommenu.Piece;

import ohos.agp.colors.RgbColor;
import ohos.app.Context;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

import com.nightonke.boommenu.ResourceTable;
import com.nightonke.boommenu.Util;

/**
 * Created by Weiping Huang at 00:00 on 16/11/27
 * For Personal Open Source
 * Contact me at 2584541288@qq.com or nightonke@outlook.com
 */

final class Ham extends BoomPiece {

    public Ham(Context context) {
        super(context);
    }

    @Override
    public void init(Color color, float cornerRadius) {
        Element backgroundDrawable = Util.getDrawable(this, ResourceTable.Graphic_piece, null);
        ((ShapeElement)backgroundDrawable).setRgbColor(RgbColor.fromArgbInt(color.getValue()));
        ((ShapeElement)backgroundDrawable).setCornerRadius(cornerRadius);
        Util.setDrawable(this, backgroundDrawable);
        invalidate();
    }

    @Override
    public void setColor(Color color) {
        ((ShapeElement)getBackgroundElement()).setRgbColor(RgbColor.fromArgbInt(color.getValue()));
        invalidate();
    }

    @Override
    public void setColorRes(int colorRes) {
        setColor(Util.getColor(getContext(), colorRes));
        invalidate();
    }
}
